import { computed, Ref } from "vue";
import { message as Message } from "ant-design-vue";

export default function BatchHook(state: { dialogOpts: Base.DialogOpts; tableRef: Ref<any> }) {
  const { dialogOpts, tableRef } = state;
  const selectRows = computed<Array<ClientWaybillManagement.ListRows>>(() => {
    return tableRef.value.xTable.getCheckboxRecords() || [];
  });
  // 修改客户备注
  const modifyRemarkHandle = () => {
    if (!selectRows.value.length) return Message.error("请勾选运单!");
    dialogOpts.title = `修改客户备注`;
    dialogOpts.width = "520px";
    dialogOpts.type = 1;
    dialogOpts.component = "ModifyRemark";
    dialogOpts.passData = selectRows.value;
    dialogOpts.visible = true;
  };
  // 修改内部备注
  const modifyInnerRemarkHandle = () => {
    if (!selectRows.value.length) return Message.error("请勾选运单!");
    dialogOpts.title = `修改内部备注`;
    dialogOpts.width = "520px";
    dialogOpts.type = 2;
    dialogOpts.component = "ModifyRemark";
    dialogOpts.passData = selectRows.value;
    dialogOpts.visible = true;
  };

  // 修改客服备注
  const modifyCustomerRemarkHandle = () => {
    if (!selectRows.value.length) return Message.error("请勾选运单!");
    dialogOpts.title = `修改客服备注`;
    dialogOpts.width = "520px";
    dialogOpts.component = "ModifyCustomerRemark";
    dialogOpts.passData = selectRows.value;
    dialogOpts.visible = true;
  };

  // 批量添加轨迹
  const addRouteInfoHandle = () => {
    if (!selectRows.value.length) return Message.error("请勾选运单!");
    dialogOpts.title = `批量添加轨迹`;
    dialogOpts.width = "520px";
    dialogOpts.component = "RouteInfo";
    dialogOpts.passData = selectRows.value;
    dialogOpts.visible = true;
  };
  // 批量导入轨迹
  const importRouteInfoHandle = () => {
    dialogOpts.title = `批量导入轨迹`;
    dialogOpts.width = "520px";
    dialogOpts.component = "ImportRouteInfo";
    dialogOpts.passData = selectRows.value;
    dialogOpts.visible = true;
  };

  // 批量导入子转单号
  const importBoxTransferNoHandle = () => {
    dialogOpts.title = `批量导入子转单号`;
    dialogOpts.width = "520px";
    dialogOpts.component = "ImportBoxTransferNo";
    dialogOpts.passData = selectRows.value;
    dialogOpts.visible = true;
  };

  //批量上传附件
  const batchUploadFileHandle = () => {
    if (!selectRows.value.length) return Message.error("请勾选运单!");
    dialogOpts.title = "批量上传附件";
    dialogOpts.width = "520px";
    dialogOpts.component = "BatchUploadFile";
    dialogOpts.passData = selectRows.value;
    dialogOpts.visible = true;
  };

  return {
    modifyRemarkHandle,
    modifyInnerRemarkHandle,
    addRouteInfoHandle,
    importRouteInfoHandle,
    importBoxTransferNoHandle,
    modifyCustomerRemarkHandle,
    batchUploadFileHandle
  };
}
